<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title>外币汇率管理</title>
<%@include file="/common/ec.jsp"%>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<script type="text/javascript">
function remove(id){
    Ext.MessageBox.confirm('提示','确认要删除外币汇率吗？', function(btn){
        if (btn == 'yes') {
        	window.location.href="${ctx}/base/currency/exchangeRate/remove.do?model.id=" + id;
        }
    });	
}

</script>
</head>
<body>
<div class="x-panel">
<div class="x-panel-header">外币汇率管理</div>
<div class="x-toolbar">
     <table width="99%">
       <tr>
        <s:form action="index" theme="simple">
	      <td width="60">外币类型：</td>
	      <td width="130">
	          <s:select id="currencyId" name="model.currency.id" 
                 list="currencyList" listKey="id" listValue="name"
				  headerKey="" headerValue="全部" cssStyle="width:112px" />
		  </td>
		  <td width="40">年度：</td>	
		  <td style="vertical-align: middle" width="80">
	            <input type="text" id="year" name="model.year" size="8" class="Wdate"
		          value='${year}' onclick="WdatePicker({dateFmt:'yyyy',skin:'whyGreen'})"/>
	      </td>
          <td><input type="submit" value="查询" class="button"/></td>
         <td align="right">
         <table> 
           <tr>
             <td><a href="#" onclick="return generateData();"><img src="${ctx}/images/icons/add.gif"/>&nbsp;生成汇率表</a></td>
           </tr>
         </table>
         </td>
         </s:form>
       </tr>
     </table>
   </div>
<div class="x-panel-body">
<ec:table items="items" var="item" retrieveRowsCallback="limit" sortRowsCallback="limit"
	    action="index.do"
		useAjax="true" doPreload="false"
		maxRowsExported="10000000" 
		pageSizeList="10,20,50,100" 
		editable="false" 
		sortable="false"	
		rowsDisplayed="10"	
		generateScript="true"	
		resizeColWidth="true"	
		classic="false"	
		width="100%" 	
		height="400px"	
		minHeight="400"
		toolbarContent="navigation|pagejump|pagesize|refresh|extend|status">
	<ec:row rowId="${item.id}">
	    <ec:column width="40" property="_s" title="No." value="${GLOBALROWCOUNT}" sortable="false" style="text-align:center"/>
		<ec:column width="60" property="currency.name" title="名称" ellipsis="true" style="text-align:center"/>
		<ec:column width="40" property="year" title="年度" style="text-align:center"/>	
		<ec:column width="55" property="januaryRate" title="1月份" style="text-align:right">	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},1);"
					name="januaryRate" size="21" value="${item.januaryRate}">					
        </ec:column>
        
        <ec:column width="55" property="februaryRate" title="2月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},2);"
					name="februaryRate" size="21" value="${item.februaryRate}"/>					
        </ec:column>
 
         <ec:column width="55" property="marchRate" title="3月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},3);"
					name="marchRate" size="21" value="${item.marchRate}"/>					
        </ec:column>
                <ec:column width="55" property="aprilRate" title="4月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},4);"
					name="aprilRate" size="21" value="${item.aprilRate}"/>					
        </ec:column>
        
                <ec:column width="55" property="mayRate" title="5月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},5);"
					name="mayRate" size="21" value="${item.februaryRate}"/>					
        </ec:column>
        
                <ec:column width="55" property="juneRate" title="6月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},6);"
					name="juneRate" size="21" value="${item.juneRate}"/>					
        </ec:column>
        
                <ec:column width="55" property="julyRate" title="7月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},7);"
					name="julyRate" size="21" value="${item.julyRate}"/>					
        </ec:column>
        
                <ec:column width="55" property="augustRate" title="8月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},8);"
					name="augustRate" size="21" value="${item.augustRate}"/>					
        </ec:column>
        
                <ec:column width="55" property="septemberRate" title="9月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},9);"
					name="septemberRate" size="21" value="${item.septemberRate}"/>					
        </ec:column>
        
                <ec:column width="55" property="octoberRate" title="10月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},10);"
					name="octoberRate" size="21" value="${item.octoberRate}"/>					
        </ec:column>   
                <ec:column width="55" property="novemberRate" title="11月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},11);"
					name="novemberRate" size="21" value="${item.novemberRate}"/>					
        </ec:column>  

        <ec:column width="55" property="decemberRate" title="12月份" >	
					<input type="text" 
					onkeyup="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'')"
					onblur="this.value=this.value.replace(/[^\d+(\.\d+)?$]/g,'');updateRate(this.value,${item.id},12);"
					name="decemberRate" size="21" value="${item.decemberRate}"/>					
        </ec:column>              															
		<ec:column width="50" property="_0" title="操作" style="text-align:center" sortable="false"> 
			<a href="#" onclick="remove(${item.id})">删除</a>	
		</ec:column>
	</ec:row>
</ec:table>
</div>
</div>
<script type="text/javascript">

function updateRate(rate, id , month) {
	if (isNaN(rate)) {
		Ext.MessageBox.show({
			title : '提示',
			minWidth : 220,
			msg : '<div style=\'width:180\';><br/>请输入数字！</div>',
			buttons : Ext.MessageBox.OK,
			icon : Ext.MessageBox.INFO
		});
		return;
	}
	$.ajax({
		url : "${ctx}/base/currency/exchangeRate/updateExchangeRate.do",
		type : "POST",
		data : {
			id : id,
			rate : rate,
			month: month
		},
		dataType : "json",
		success : function(result) {
			if (result.success) {
				refresh();
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			Ext.MessageBox.show({
				title : '提示',
				minWidth : 220,
				msg : XMLHttpRequest.responseText,
				buttons : Ext.MessageBox.OK,
				icon : Ext.MessageBox.INFO
			});
		}
	});
}


function generateData(){
	var year = document.getElementById('year').value;
	var currencyId = document.getElementById('currencyId').value;	
	var name = document.getElementById("currencyId").options[document.getElementById("currencyId").options.selectedIndex].text;
    if (year == null || year == '') {
        Ext.MessageBox.show({
             title:'提示',
             minWidth:220,
             msg:'<div style=\'width:180\';><br/>请选择年度！</div>',
             buttons:Ext.MessageBox.OK,
             icon:Ext.MessageBox.INFO
        });
        return false;
    }
    var isAllCurrency;
    if (currencyId == null || currencyId == '') {
    	isAllCurrency = "全部币种";
    }else {
    	isAllCurrency = name;
    }
    
    Ext.MessageBox.confirm('提示', '您确定生成【' + isAllCurrency + '】的【' + year + '】年度的汇率表吗？', function(btn){
        if (btn == 'yes') {
        	//加载进度条
        	loadProgress();
        	
		      $.ajax({
		    	    url: '${ctx}/base/currency/exchangeRate/generateData.do',
			  		type: 'post',
			  		dataType: 'json',
			  		data: {currencyId : currencyId, year : year},
			  		success: function(rst, textStatus){
			  	  		if(rst.result == "success"){ 
			  	  		    Ext.MessageBox.hide(); //隐藏进度条
		    		        Ext.MessageBox.show({
		    		             title:'提示',
		    		             minWidth:220,
		    		             msg:'<div style=\'width:180\';><br/>已成功生成币种汇率表！</div>',
		    		             buttons:Ext.MessageBox.OK,
		    		             icon:Ext.MessageBox.INFO,
		    		             fn:function (){document.getElementById("index").submit();}
		    		        });		    		        
			  	  	  	}
			  	  		if(rst.result == "error"){	 
			  	  		    Ext.MessageBox.hide(); //隐藏进度条
		    		        Ext.MessageBox.show({
		    		             title:'提示',
		    		             minWidth:220,
		    		             msg:'<div style=\'width:180\';><br/>请您重新登录系统！</div>',
		    		             buttons:Ext.MessageBox.OK,
		    		             icon:Ext.MessageBox.INFO
		    		        });
                            return false;
			  	  	  	}			  	  		
			  		}
			     });
       }
    });
}

//加载进度条	
function loadProgress() {
	Ext.MessageBox.show({
		title : '提示',
		msg : '数据生成中,请耐心等待···',
		progress : true,
		width : 300,
		wait : true,
		waitConfig : {
			interval : 300,//0.6s进度条自动加载一定长度
			duration : 120000,
			fn : function() {
				Ext.MessageBox.hide();//让进度条消失
				Ext.MessageBox.show({
					title : '提示',
					minWidth : 220,
					minHeight : 220,
					msg : '系统超时！',
					buttons : Ext.MessageBox.OK
				//icon : Ext.MessageBox.INFO,
				});
			}
		},
		closable : true
	});
}




function refresh() {
  ECSideUtil.reload('ec');
}
</script>

</body>
</html>